<!DOCTYPE html>
<html>

<head>
    <link rel="icon" href="/favicon.png" type="image/x-icon">
    <meta charset="UTF-8" />
    <title>Search</title>
    {% load static %}
    <script src="{% static 'js/bootstrap.bundle.min.js' %}"></script>
    <link rel="stylesheet" href="{% static 'css/bootstrap.min.css' %}">
    <link rel="stylesheet" href="{% static 'icon/bootstrap-icons.min.css' %}">
    <style>
        .page-header {
            margin-top: 10px;
            padding-bottom: 5px;
            border-bottom: 1px solid #eee;
        }
    </style>
</head>

<body>
    {% block content %}
    <div class="container">
        {% include 'common/nav.html' %}
        
        <div class="row  d-flex justify-content-center align-items-center">
            <div class="col">
                <form id="advanced-search-form" method="POST" action="{% url 'advanced_search' %}">
                    {% csrf_token %}
                    <div id="query-conditions">
                        <!-- 查询条件将在这里动态添加 -->
                    </div>

                    <div class="form-group mt-3">
                        <button type="button" id="add-condition" class="btn btn-secondary">+ 添加条件</button>
                        <button type="submit" class="btn btn-primary">搜索</button>
                        <button type="button" id="reset-form" class="btn btn-outline-danger">重置</button>
                    </div>
                </form>

                <div id="search-results" class="mt-4"></div>
            </div>

            <!-- 条件模板 (隐藏) -->
            <div id="condition-template" style="display:none;">
                <div class="condition-card card mb-3">
                    <div class="card-body">
                        <div class="row g-2 align-items-center">
                            <div class="col-md-2">
                                <select class="form-control field-select" name="field" required>
                                    <optgroup label="基础属性">
                                        <option value="title" data-type="STR" data-isbasic="true">标题</option>
                                        <option value="description" data-type="STR" data-isbasic="true">描述</option>
                                        <option value="uploader" data-type="STR" data-isbasic="true">上传者</option>
                                        <option value="date" data-type="DATE" data-isbasic="true">上传日期</option>
                                    </optgroup>
                                    <optgroup label="标签" id="tags-optgroup">
                                        <!-- 标签选项将通过API动态加载 -->
                                    </optgroup>
                                </select>
                            </div>

                            <div class="col-md-2">
                                <select class="form-control operator-select" name="operator" required>
                                    <!-- 运算符将通过JS动态填充 -->
                                </select>
                            </div>

                            <div class="col-md-4 value-container">
                                <!-- 值输入区域将通过JS动态生成 -->
                            </div>

                            <div class="col-md-2">
                                <select class="form-control logic-select" name="logic">
                                    <option value="AND">AND</option>
                                    <option value="OR">OR</option>
                                </select>
                            </div>

                            <div class="col-sm-1">
                                <div class="form-check">
                                    <input type="checkbox" class="form-check-input not-checkbox" name="not"
                                        id="not-{id}">
                                    <label class="form-check-label" for="not-{id}">NOT</label>
                                </div>
                            </div>

                            <div class="col-md-1">
                                <button type="button" class="btn btn-danger remove-condition">×</button>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    </div>
    <script>const searchURL="{% url 'advanced_search' %}"</script>
    <script src="{% static 'site/adv_search/main.js' %}"></script>

    <style>
        .condition-card {
            padding: 15px;
            border: 1px solid #dee2e6;
            border-radius: 5px;
            margin-bottom: 15px;
            background-color: #f8f9fa;
        }

        .condition-card .card-body {
            padding: 5px;
        }

        .remove-condition {
            font-size: 1.2em;
            line-height: 1;
            padding: 0 0.5em;
            border: none;
            background: none;
            color: #dc3545;
        }

        .multi-value-input textarea {
            min-height: 100px;
        }

        .range-input .form-control,
        .multi-value-input .form-control {
            margin-bottom: 5px;
        }

        .form-text {
            font-size: 0.8em;
            color: #6c757d;
        }

        #search-results {
            min-height: 200px;
        }

        .spinner-border {
            vertical-align: text-top;
        }
    </style>
    {% endblock %}
</body>

</html>